package webserver;

import java.io.*;
import java.net.*;
import java.util.concurrent.*;

import mapserver.Mapserver;
public class Server {

	private int port = 8000;
	private ServerSocket serverSocket;
	private ExecutorService executorService;
	private Mapserver mapserver = null;
	public Server() throws Exception
	{
		serverSocket = new ServerSocket(port);
		executorService = Executors.newCachedThreadPool();
		mapserver = new Mapserver();
		//mapserver.initialmapserver();
		System.out.println("The web server starts");
		System.out.println("The map server starts");
		
	}
	
	public void service()
	{
		while(true)
		{
			Socket socket = null;
			try{
				socket = serverSocket.accept();
				executorService.execute(new Handler(socket,mapserver));
			}catch(Exception e)
			{
				System.out.println(e.getMessage());
			}
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try{
			new Server().service();
			}catch(Exception exception)
			{
			   System.out.println(exception.getMessage());
			}
	}

}
